Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Displaying Raw • Download


sbapp/kivymd/toast/androidtoast/androidtoast.py 0.7.2 (6fcff084) Text, 2.36 KB

T8b949e"""
AndroidToast
============

.. rubric:: Native implementation of toast for Android devices.

.. code-block:: python

# Will be automatically used native implementation of the toast
# if your application is running on an Android device.
# Otherwise, will be used toast implementation
# from the kivymd/toast/kivytoast package.

from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager

from kivymd.toast import toast
from kivymd.app import MDApp

KV = '''
MDScreen:

MDFlatButton:
text: "My Toast"
pos_hint:{"center_x": .5, "center_y": .5}
on_press: app.show_toast()
'''


class Test(MDApp):
def build(self):
return Builder.load_string(KV)

def show_toast(self):
toast("Hello World", True, 80, 200, 0)


Test().run()
"""

Te6edf3__all__ Tff7b72= Tb4b4b4(Ta5d6ff"Ta5d6fftoastTa5d6ff"Tb4b4b4,Tb4b4b4)

Tff7b72from T7ee787kivy Tff7b72import Te6edf3platform

Tff7b72if Te6edf3platform Tff7b72!= Ta5d6ff"Ta5d6ffandroidTa5d6ff"Tb4b4b4:
Tff7b72raise Tf85149TypeErrorTb4b4b4(
Ta5d6fffTa5d6ff"Tffd700{Te6edf3platformTff7b72.Td2a8ffcapitalizeTb4b4b4(Tb4b4b4)Tffd700}Ta5d6ff platform does not support Android ToastTa5d6ff"
Tb4b4b4)

Tff7b72from T7ee787androidT7ee787.T7ee787runnable Tff7b72import Te6edf3run_on_ui_thread
Tff7b72from T7ee787jnius Tff7b72import Te6edf3autoclass

Te6edf3activity Tff7b72= Te6edf3autoclassTb4b4b4(Ta5d6ff"Ta5d6fforg.kivy.android.PythonActivityTa5d6ff"Tb4b4b4)Tff7b72.Td2a8ffmActivity
Te6edf3Toast Tff7b72= Te6edf3autoclassTb4b4b4(Ta5d6ff"Ta5d6ffandroid.widget.ToastTa5d6ff"Tb4b4b4)
Te6edf3String Tff7b72= Te6edf3autoclassTb4b4b4(Ta5d6ff"Ta5d6ffjava.lang.StringTa5d6ff"Tb4b4b4)


Tf0883e@run_on_ui_thread
Tff7b72def Td2a8fftoastTb4b4b4(Te6edf3textTb4b4b4, Te6edf3length_longTff7b72=Tff7b72FalseTb4b4b4, Te6edf3gravityTff7b72=T79c0ff0Tb4b4b4, Te6edf3yTff7b72=T79c0ff0Tb4b4b4, Te6edf3xTff7b72=T79c0ff0Tb4b4b4)Tb4b4b4:
T8b949e"""
Displays a toast.

:param length_long: the amount of time (in seconds) that the toast is
visible on the screen;
:param text: text to be displayed in the toast;
:param short_duration: duration of the toast, if `True` the toast
will last 2.3s but if it is `False` the toast will last 3.9s;
:param gravity: refers to the toast position, if it is 80 the toast will
be shown below, if it is 40 the toast will be displayed above;
:param y: refers to the vertical position of the toast;
:param x: refers to the horizontal position of the toast;

Important: if only the text value is specified and the value of
the `gravity`, `y`, `x` parameters is not specified, their values will
be 0 which means that the toast will be shown in the center.
"""

Te6edf3duration Tff7b72= Te6edf3ToastTff7b72.Td2a8ffLENGTH_SHORT Tff7b72if Te6edf3length_long Tff7b72else Te6edf3ToastTff7b72.Td2a8ffLENGTH_LONG
Te6edf3t Tff7b72= Te6edf3ToastTff7b72.Td2a8ffmakeTextTb4b4b4(Te6edf3activityTb4b4b4, Te6edf3StringTb4b4b4(Te6edf3textTb4b4b4)Tb4b4b4, Te6edf3durationTb4b4b4)
Te6edf3tTff7b72.Td2a8ffsetGravityTb4b4b4(Te6edf3gravityTb4b4b4, Te6edf3xTb4b4b4, Te6edf3yTb4b4b4)
Te6edf3tTff7b72.Td2a8ffshowTb4b4b4(Tb4b4b4)


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────